package com.superb.common.feign.dynamic;

import com.superb.common.feign.dynamic.service.DynamicFeignService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * @Author: ajie
 * @CreateTime: 2024-05-15 17:43
 */
@Component
public class DynamicFeignClient {

    @Resource
    private DynamicFeignClientFactory feignClientFactory;

    /**
     * 通用 post
     *
     * @param feignName 服务名称
     * @param path      path
     * @param params    参数
     * @return
     */
    public Object executePostApiByServiceName(String feignName, String path, Object params) {
        DynamicFeignService dynamicService = this.feignClientFactory.getFeignBySeviceName(DynamicFeignService.class, feignName);
        return dynamicService.executePostApi(path, params);
    }

    public Object executePostApiByUrl(String url, String path, Object params) {
        DynamicFeignService dynamicService = this.feignClientFactory.getFeignByUrl(DynamicFeignService.class, url);
        return dynamicService.executePostApi(path, params);
    }

    /**
     * 通用 get
     *
     * @param feignName 服务名称
     * @param path      path
     * @param params    参数
     * @return
     */
    public Object executeGetApiBySeviceName(String feignName, String path, Object params) {
        DynamicFeignService dynamicService = this.feignClientFactory.getFeignBySeviceName(DynamicFeignService.class, feignName);
        return dynamicService.executeGetApi(path, params);
    }

    public Object executeGetApiByUrl(String url, String path, Object params) {
        DynamicFeignService dynamicService = this.feignClientFactory.getFeignByUrl(DynamicFeignService.class, url);
        return dynamicService.executeGetApi(path, params);
    }

}
